package com.jiangxjsy.admin.support;

import com.alibaba.fastjson.JSONObject;
import com.jiangxjsy.model.admin.entity.AdminMenu;
import org.springframework.stereotype.Component;

import java.util.Objects;
import java.util.Set;

/**
 * wukong-crm-master
 * 蒋胜宇
 * 2025/6/8 14:58
 */

@Component
public class AdminRoleSupport {
    /**
     * 创建菜单
     *
     * @param adminMenuList 菜单列表
     * @param parentId 父级菜单 ID
     * @return JSONObject
     */
    public JSONObject createMenu(Set<AdminMenu> adminMenuList, Long parentId) {
        JSONObject jsonObject = new JSONObject();
        adminMenuList.forEach(adminMenu -> {
            if (Objects.equals(parentId, adminMenu.getParentId())) {
                if (Objects.equals(1L, adminMenu.getMenuType())) {
                    JSONObject object = createMenu(adminMenuList, adminMenu.getMenuId());
                    if (!object.isEmpty()) {
                        jsonObject.put(adminMenu.getRealm(), object);
                    }
                } else {
                    jsonObject.put(adminMenu.getRealm(), Boolean.TRUE);
                }
            }
        });
        return jsonObject;
    }

    /**
     * 角色类型转换
     *
     * @param type 角色类型
     * @return 角色类型名称
     */
    public String roleTypeCaseName(Integer type) {
        String name;
        switch (type) {
            case 1:
                name = "系统管理角色";
                break;
            case 2:
                name = "客户管理角色";
                break;
            case 7:
                name = "办公管理角色";
                break;
            case 8:
                name = "项目管理角色";
                break;
            case 9:
                name = "人力资源管理角色";
                break;
            case 10:
                name = "进销存管理角色";
                break;
            default:
                name = "自定义角色";
        }
        return name;
    }
}
